<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author   test
 *
 */
namespace osc\admin\controller;
//require_once '/extend/PHPExcel.php';

use osc\common\service\Excel;
use osc\common\controller\AdminBase;
use think\Db;
class Export extends AdminBase{
	
	protected function _initialize(){
		parent::_initialize();
		$this->assign('breadcrumb1','导出');
		$this->assign('breadcrumb2','导出');		
	}

	
	function export_order()
	{
		$param = input('param.');


	 	


		$sql = 'select od.order_num_alias, od.pay_subject,od.total,ad.province_name,ad.city_name,ad.country_name,ad.address,ad.name,ad.telephone from osc_order od,
(select a2.*,b2.area_name province_name from (select a1.*,b1.area_name country_name from (select od.address_id,od.address,od.`name`,od.telephone,od.city_id,od.country_id,od.province_id,oa.area_name city_name 
from osc_area oa, osc_address od  where oa.area_id = od.city_id) a1 ,osc_area b1 where a1.country_id = b1.area_id) a2, osc_area b2 where a2.province_id = b2.area_id) ad where od.address_id = ad.address_id';



		if(isset($param['status'])){
			$sql = $sql.' and od.order_status_id = '.$param['status'];
		}

		if(isset($param['user_name'])){
			$sql = $sql.' and od.username = '.$param['user_name'];
		}
		//var_dump($sql);

		if(isset($param['pay_subject'])){
			$sql = $sql." and od.pay_subject = '".$param['pay_subject']."'";
		}
		if(isset($param['begin_time'])){
			$sql = $sql." and od.pay_time < ".strtotime($param['begin_time'])."";
		}
		if(isset($param['end_time'])){
			$sql = $sql." and od.pay_time > ".strtotime($param['end_time'])."";
		}

//		echo'<pre>';print_r($sql);exit;

		$result = Db::query($sql); 


		$excel=new Excel();
       
        $field=["order_num_alias"=>"订单号","pay_subject"=>"商品名","total"=>"使用金豆","province_name"=>"省","city_name"=>"市","country_name"=>"县，区","address"=>"详细地址","name"=>"收货人姓名","telephone"=>"联系电话"];

        $excel->setExcelName("订单导出")
        ->createSheetByList("待处理",$result,$field)
        ->downloadExcel();
	}


	function export_wd()
	{
		$param = input('param.');


	 	


		$sql = 'select username,num,real_money,bankname,bankaccountname,bankaccount from osc_goldstonewd  where pay_status = 0 order by creat_time desc';



		//var_dump($sql);

		$result = Db::query($sql); 


		$excel=new Excel();
       
        $field=["username"=>"手机号码","num"=>"提现额度","real_money"=>"到账额度","bankname"=>"银行","bankaccountname"=>"开户名","bankaccount"=>"账号"];

        $excel->setExcelName("提现导出")
        ->createSheetByList("提现处理",$result,$field)
        ->downloadExcel();
	}

	function export_iswd()
	{
		$param = input('param.');


	 	


		$sql = 'select username,num,real_money,bankname,bankaccountname,bankaccount from osc_goldstonewd  where pay_status = 1 order by creat_time desc';



		//var_dump($sql);

		$result = Db::query($sql); 


		$excel=new Excel();
       
        $field=["username"=>"手机号码","num"=>"提现额度","real_money"=>"到账额度","bankname"=>"银行","bankaccountname"=>"开户名","bankaccount"=>"账号"];

        $excel->setExcelName("提现导出")
        ->createSheetByList("提现处理",$result,$field)
        ->downloadExcel();
	}
	



}
?>